//登录页面
<template>
	<div>
		<van-nav-bar title="登录" />
		
		<van-cell-group inset>
			<van-field v-model="user.username" label="用户名" placeholder="用户名" />
			<van-field v-model="user.password" type="password" label="密码" placeholder="密码" />
		</van-cell-group>
		<div style="margin: 16px;">
			<van-button round block type="primary" @click="Login">
				登录
			</van-button>
			<div style="text-align: end;margin-top: 10px;">
				<router-link to="/register">免费注册</router-link>
			</div>
		</div>
	</div>
</template>

<script>
  import axios from '../utils/request'
	import { Toast } from 'vant';
	export default {
		computed: {

		},
		data() {
			return {
				user: {
					username: 'lan',
					password: '123'
				}
			}
		},
		mounted() {

		},
		methods: {
			Login() {
			
				const params = {
					username: this.user.username,
					password: this.user.password
				}
				Toast.loading({
				  message: '登录中...'
				});
				axios.post('/login', params)
					.then(response => {
							//JSON.stringify 对象转换为JSON字符串
							localStorage.setItem('userInfo', JSON.stringify(response.data.data.userInfo))
							localStorage.setItem('token', response.data.data.token)
							this.$router.push('/index')
							Toast.success(response.data.msg);
					})
					.catch(error => {
						console.log(error.response);
					});
			}
		}
	}
</script>

<style>

</style>